//-----------------Sonic CD LaserTrap Script-------------------//
//-------Scripted by makasinaaaa & Christian Whitehead--------//
// Yeah...

// Aliases
#alias Object.Value1	:	Object.Timer
#alias Object.Value2	:	Object.YDrawPos
#alias Object.Value3	:	Object.T1
#alias Object.Value4	:	Object.T2
#alias Object.Value5	:	Object.T3
#alias Object.Value5	:	Object.T4
#alias Object.Value6	:	Object.T5
#alias Object[24].PropertyValue	:	HUD.CurrentTimePeriod



#alias Object.PropertyValue		:	PushButton.Pressed	

 
// Priority
#alias 0	:	PRIORITY_BOUNDS
#alias 1	:	PRIORITY_ACTIVE

// States
#alias 0	:	LASER_ON
#alias 1	:	LASER_OFF

sub ObjectMain
	if Object.OutOfBounds == true
		Object.State    = LASER_ON
		Object.Priority = PRIORITY_BOUNDS
	end if
	if PushButton[-1].Pressed == true
		Object.State    = LASER_OFF
	end if
end sub

sub ObjectPlayerInteraction
	if Object.State == LASER_ON
		PlayerObjectCollision(C_BOX, -8, -8, 8, 8)
		TempValue0 = 0
		TempValue1 = -16
		TempValue2 = 0
		while TempValue0 <= Object.PropertyValue
			TempValue0++
			PlayerObjectCollision(C_BOX, -8, TempValue1, 8, TempValue2)
			PlayerObjectCollision(C_TOUCH, -9, TempValue1, 9, TempValue2)
			if CheckResult == true
				CallFunction(Player_Hit)
			end if
			TempValue1 -= 16
			TempValue2 += 0
		loop
		TempValue1 += 8
		TempValue2 += 0
	end if
end sub


sub ObjectDraw
	if Object.State == LASER_ON
		Object.Timer += 8
	end if
		if Object.Timer > 678
			Object.Timer = 0
		end if
		
	if  Object.Timer <= 8
		if Object.OutOfBounds == false
			PlayStageSFX(7, false)
		end if
	end if
	if  Object.Timer <= 20
		Object.State = LASER_ON
		Object.T1 = 3
		Object.T2 = 4
		Object.T3 = 5
	else
		if  Object.Timer <= 40
			Object.T1 = 0
			Object.T2 = 1
			Object.T3 = 2
		else
			if  Object.Timer <= 60
				Object.T1 = 3
				Object.T2 = 4
				Object.T3 = 5
			else
				if  Object.Timer <= 100
					Object.T1 = 0
					Object.T2 = 1
					Object.T3 = 2
				else
					if  Object.Timer <= 120
						Object.T1 = 12
						Object.T2 = 13
						Object.T3 = 14
					else
						if  Object.Timer <= 140
							Object.T1 = 0
							Object.T2 = 1
							Object.T3 = 2
						else
							if  Object.Timer <= 160
								Object.T1 = 3
								Object.T2 = 4
								Object.T3 = 5
							else
								if  Object.Timer <= 270
									Object.T1 = 0
									Object.T2 = 1
									Object.T3 = 2
								else
									if  Object.Timer <= 310
										Object.T1 = 6
										Object.T2 = 7
										Object.T3 = 8
									else
										if  Object.Timer <= 330
											Object.T1 = 12
											Object.T2 = 13
											Object.T3 = 14
										else
											if  Object.Timer <= 350
												Object.T1 = 0
												Object.T2 = 1
												Object.T3 = 2
											else
												if  Object.Timer <= 370
													Object.T1 = 9
													Object.T2 = 10
													Object.T3 = 11
												else
													if  Object.Timer <= 410
														Object.T1 = 0
														Object.T2 = 1
														Object.T3 = 2
													else
														if  Object.Timer > 410
															Object.Timer++
															Object.Timer++
															Object.Timer++
															Object.Timer++
															Object.State = LASER_OFF
														end if
													end if
												end if
											end if
										end if
									end if
								end if
							end if
						end if
					end if
				end if
			end if
		end if
	end if					

	switch Object.Timer
		case 0
		case 1
			break
		case 2
		case 3
			break
		case 4
		case 5
			break
		case 6
		case 7
		case 8
		case 9
			break
		case 10
		case 11
			break
		case 12
		case 13
			break
		case 14
		case 15
			break
		case 16
		case 17
		case 18
		case 19
		case 20
		case 21
		case 22
		case 23
		case 24
		case 25
		case 26
		case 27
		case 28
		case 29
		case 30
		case 31
		case 32
		case 33
		case 34
		case 35
		case 36
		case 37
		case 38
		case 39
		case 40
			break
		case 41
		case 42
		case 43
		case 44
			break
		case 45
		case 46
			break
		case 47
		case 48
			break
		case 47
		case 48
			break
		case 49
		case 50
		case 51
		case 52
			break
	end switch
	if Object.Timer > 52
	end if
	DrawSprite(Object.T1)
	TempValue0 = 0
	TempValue1 = 16
	while TempValue0 < Object.PropertyValue
		TempValue3  = -512
		TempValue3  *= TempValue1
		TempValue3 <<= 7
		TempValue3  += Object.YPos

		DrawSpriteXY(Object.T2, Object.XPos, TempValue3)

		TempValue0++

		TempValue1 += 16
	loop

	Object.YDrawPos = -512
	Object.YDrawPos  *= TempValue1
	Object.YDrawPos <<= 7
	Object.YDrawPos  += Object.YPos
	Object.YDrawPos  &= 0xFFFF0000 // Truncate the value

	DrawSpriteXY(Object.T3, Object.XPos, Object.YDrawPos)
end sub


sub ObjectStartup
	LoadSpriteSheet("R2/Objects3.gif")
	
	// Set this object to always active
	ArrayPos0 = 32
	while ArrayPos0 < 1056
		if Object[ArrayPos0].Type == TypeName[LaserTrap]
			Object[ArrayPos0].Priority = PRIORITY_ACTIVE
		end if
		ArrayPos0++
	loop
	
	TempValue0 = HUD.CurrentTimePeriod
	TempValue1 = 1
	TempValue0 *= 17
	TempValue1 += TempValue0 
	
	SpriteFrame(-8, -8, 16, 16, TempValue1, 18)			// #0 - Bottom
	SpriteFrame(-8, -8, 16, 16, 1, 171)		// #1 - Laser 
	SpriteFrame(-8, -8, 16, 16, TempValue1, 1)			// #2 - Top
	
	SpriteFrame(-8, -8, 16, 16, TempValue1, 52)			// #3 - Bottom
	SpriteFrame(-8, -8, 16, 16, 1, 188)			// #4 - Laser 
	SpriteFrame(-8, -8, 16, 16, TempValue1, 35)			// #5 - Top
	
	SpriteFrame(-8, -8, 16, 16, TempValue1, 86)			// #6 - Bottom
	SpriteFrame(-8, -8, 16, 16, 1, 205)			// #7 - Laser 
	SpriteFrame(-8, -8, 16, 16, TempValue1, 69)			// #8 - Top
	
	SpriteFrame(-8, -8, 16, 16, TempValue1, 120)			// #9 - Bottom
	SpriteFrame(-8, -8, 16, 16, 1, 222)			// #10 - Laser 
	SpriteFrame(-8, -8, 16, 16, TempValue1, 103)			// #11 - Top
	
	SpriteFrame(-8, -8, 16, 16, TempValue1, 154)			// #12 - Bottom
	SpriteFrame(-8, -8, 16, 16, 1, 239)			// #13 - Laser 
	SpriteFrame(-8, -8, 16, 16, TempValue1, 137)			// #14 - Top
end sub 